package com.yc.cloud.openai.portal.handler;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.openai.portal.utils.WebClientUtil;
import lombok.val;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class CustomExceptionHandler {

    @ExceptionHandler(WebClientUtil.CustomWebClientException.class)
    public ResponseResult<String> handleWebClientException(WebClientUtil.CustomWebClientException ex) {
        // 获取自定义的 ErrorResponse 对象
        val errorResponse = ex.getErrorResponse();
        // 返回 ResponseEntity，设置状态码和错误信息
        return ResponseResult.failed(errorResponse.getMessage());
    }
}
